package cn.xs.surveypark.struts2.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.xs.surveypark.domain.Survey;
import cn.xs.surveypark.domain.User;
import cn.xs.surveypark.service.SurveyService;

/**
 * 
 * @author Administrator
 *
 */
@Controller
@Scope("prototype")
public class SurveyAction extends BaseAction<Survey> implements SessionAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = -9040261838677841411L;
	
	private Map<String, Object> sessionMap;
	
	//我的调查问题
	private List<Survey> mySurvey;
	

	@Resource
	private SurveyService surveyService;
	
	/**
	 * 新建调查
	 */
	public String newSurvey(){
		User u = (User) sessionMap.get("user");
		this.model = surveyService.newSurvey(u);
		return "designSurveyPage";
	}
	
	/**
	 * 查询我的调查
	 */
	public String mySurveys(){
		
		User user = (User) sessionMap.get("user");
		this.mySurvey = surveyService.findMySurvey(user);
		return "mySurveyListPage";
	}

	//注入session map 耦合度低
	@Override
	public void setSession(Map<String, Object> session) {
		// TODO Auto-generated method stub
		this.sessionMap = session;
	}
	
	public List<Survey> getMySurvey() {
		return mySurvey;
	}
	
	public void setMySurvey(List<Survey> mySurvey) {
		this.mySurvey = mySurvey;
	}
	
}
